package org.agora.photogallery.client.presenter;

import org.agora.photogallery.client.event.PhotoThumbnailClickedEvent;
import org.agora.photogallery.client.event.PhotoThumbnailClickedHandler;
import org.agora.photogallery.client.event.ShowGalleryEvent;
import org.agora.photogallery.client.event.ShowGalleryEventHandler;
import org.agora.photogallery.client.model.Photo;
import org.agora.photogallery.client.service.PhotoService;
import org.agora.photogallery.client.view.PhotoView;

import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.inject.Inject;

public class PhotoPresenter implements Presenter, PhotoView.PhotoPresenter, PhotoThumbnailClickedHandler, ShowGalleryEventHandler {
	private final PhotoView view;
	private final PhotoService service;
	private final HandlerManager eventBus;
	
	@Inject
	public PhotoPresenter(PhotoView view, PhotoService service, HandlerManager eventBus){
		this.view = view ;
		this.service = service ; 
		this.eventBus = eventBus;
		eventBus.addHandler(PhotoThumbnailClickedEvent.TYPE, this);
		eventBus.addHandler(ShowGalleryEvent.TYPE, this);	
	}
	
	@Override
	public void present(HasWidgets container) {
		container.add(view.asWidget());

	}

	@Override
	public void onItemClicked(Photo p) {
		
	}

	@Override
	public void onPhotoThumbnailClicked(PhotoThumbnailClickedEvent e) {
		Photo p = e.getPhoto();
		view.setData(p);
		
	}

	@Override
	public void OnShowEvent(ShowGalleryEvent event) {
		view.hide();
		
	}
	

}
